$(function () {
    // 图片验证码
   var img_captcha = $('.img_captcha');
   img_captcha.click(function () {
       var timestrap = new Date().getTime();
       var img_src = $(this).attr('src');
       img_src = img_src.split('?')[0];
       img_src = img_src + '?' + timestrap;
       $(this).attr('src', img_src)
   });
   // 注册
    var submit_btn = $('#submit-btn');
   submit_btn.on('click', function () {
       var telephone_input = $('input[name="telephone"]');
       var password_input1 = $('input[name="password1"]');
       var password_input2 = $('input[name="password2"]');
       var username_input = $('input[name="username"]');
       var img_captcha_input = $('input[name="img_captcha"]');
       juneajax.post({
           'url': '/signup/',
           'data': {
               'telephone': telephone_input.val(),
               'username': username_input.val(),
               'password1': password_input1.val(),
               'password2': password_input2.val(),
               'img_captcha': img_captcha_input.val()
           },
           'success': function (data) {
               if (data['code']==200) {
                   junealert.alertSuccess('恭喜！注册成功。', function () {
                       var referer_url = $('#referer_url').text();
                       if (referer_url && referer_url != 'None'){
                           window.location = referer_url
                       }else{
                           window.location = '/'
                       }
                   })
               }else{
                   var danger_info = $('#danger-info');
                   danger_info.text('*'+data['message'])
               }
           },
           'fail': function (error) {
               junealert.alertErrorToast(error)
           }

       })
   })
});